import {defHttp} from '/@/utils/http/axios';
import {Modal} from 'ant-design-vue';
import {TreeModel} from '/@/api/model/baseModel'

export enum Api {
  page = "/system-service/area/page",
  get = "/system-service/area/get",
  listTreeSelect = "/system-service/area/listTreeSelect",

  save = "/system-service/area/save",
  edit = "/system-service/area/update",
  updateStatus = "/system-service/area/updateStatus",
  delete = "/system-service/area/delete",
}

export interface Area extends TreeModel<Area> {
  id?: string; // 区域Id(编码)
  areaName?: string; // 区域名称
  areaType?: string; // 区域类型
}

export const pageArea = (params : Area | any) => {
  return defHttp.get({url: Api.page, params});
}

export const getArea = (params?: Area | any) => defHttp.get<Area>({ url: Api.get, params });
export const listAreaTreeSelect = (params?: Area | any) => defHttp.get<Area>({ url: Api.listTreeSelect, params });

export const saveOrUpdateArea = (params : Area | any, isUpdate) => {
  let url = isUpdate ? Api.edit : Api.save;
  return defHttp.post({url: url, params});
}

export const updateAreaStatus = (params : Area | any) => {
  return defHttp.put({url: Api.updateStatus, params}, {joinParamsToUrl: true});
}

export const deleteArea = (params: Area | any, handleSuccess) => {
  Modal.confirm({
    title: '确认删除',
    content: '是否删除当前区域以及子区域',
    okText: '确认',
    cancelText: '取消',
    onOk: () => {
      return defHttp.delete({url: Api.delete, data: params}, {joinParamsToUrl: true}).then(() => {
        handleSuccess();
      });
    }
  });
}
